home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / prodpack.zip / DB4PPSRC.EXE / _CAT4DBF.PRG next >
Text File  |  1993-05-04  |  4KB  |  126 lines

  1. PROCEDURE _Cat4Dbf
  2. PARAMETERS pc_fname, pc_result, pl_isqbe, pl_catopnd
  3. *--------------------------------------------------------------------
  4. * NAME
  5. *   _Cat4Dbf - determine name of DBF or QBE associated with a form
  6. *
  7. * DESCRIPTION
  8. *   The _Cat4Dbf procedure will determine the DBF or view that is
  9. *   related to the <pc_fname> file.  If _Cat4Dbf found a match based
  10. *   on the catalog CODE field, it will put the DBF or view name
  11. *   in <pc_result>.  If the match was a view, it will set <pl_isqbe>
  12. *   to a true value, otherwise it will be a false value.
  13. *
  14. *   If the catalog file is opened and you want to keep it open,
  15. *   set the value of <pl_catopnd> to a true value.
  16. *
  17. * SYNOPSIS
  18. *   DO _Cat4Dbf WITH <pc_fname>, <pc_result>, <pl_isqbe>, <pl_catopnd>
  19. *
  20. * EXAMPLE
  21. *   *-- Find the DBF for GOODS.SCR
  22. *   lc_dbf = ""                         && Set up the result DBF name
  23. *   ll_qbe = .F.                        && Set up the was it a QBE flag
  24. *   DO _Cat4Dbf WITH "GOODS.SCR", lc_dbf, ll_qbe, .F.
  25. *   IF .NOT. ISBLANK( lc_dbf )          && If a DBF was found
  26. *     ...                               && Put your DBF code here
  27. *   ENDIF
  28. *
  29. * PARAMETERS
  30. *   pc_fname    = name of the SCR file to find DBF or QBE with
  31. *   pc_result   = returns name of matching DBF or QBE file
  32. *   pl_isqbe    = returns .T. if SCR matches QBE file
  33. *   pl_catopnd  = .T. if catalog is already opened
  34. *
  35. * DEPENDENCIES
  36. *   Creates the following public memory variables:
  37. *     FXC_CTAG  = Value of the catalog TAG field for the given SCR file.
  38. *                 Will be "PRG" for a Master-Detail form, blank for others.
  39. *                 This varaible is used by _FXExit to determine the
  40. *                 generate style without having to scan the SCB file.
  41. *
  42. *   Calls:  _CatOpen  - Open a dBASE catalog file
  43. *           _CatClose - Close a dBASE catalog file
  44. *           _CatCode  - Determine the catalog code for a specified file
  45. *
  46. *   Called by:  _FXUseIt - Use the correct DBF or View based on extensions
  47. *
  48. * VARIABLES
  49. *   lc_alias    = Name of ALIAS() for current WA
  50. *   ll_opened   = If the catalog file was opened, then it's set to .T.,
  51. *                 else it will be .F.
  52. *   ll_catalog  = State of CATALOG,  .T. if on, .F. if off
  53. *   ln_code     = Return CODE field for catalog file.  If 0, then the
  54. *                 file doesn't have a related DBF or QBE file.
  55. *--------------------------------------------------------------------
  56.  
  57.   PRIVATE lc_alias, ll_opened, ll_catalog, ln_code
  58.  
  59.   pc_result = ""                        && Result of the matching DBF/QBE
  60.  
  61.   lc_alias = ALIAS()                    && Save the alias for any open dbf
  62.   ll_opened = .F.                       && Let others know catalog not open
  63.  
  64.   ll_catalog = SET( "CATALOG" ) = "ON"
  65.   SET CATALOG OFF                       && Force the catalog off
  66.  
  67.   IF .NOT. pl_catopnd                   && If the catalog is not open
  68.  
  69.     DO _CatOpen WITH ll_opened          && Try and open it
  70.  
  71.   ELSE
  72.  
  73.     ll_opened = .T.                     && Signal that the catalog is open
  74.  
  75.   ENDIF
  76.  
  77.   RELEASE FXC_ctag
  78.   PUBLIC FXC_ctag
  79.   FXC_ctag = ""
  80.  
  81.   IF ll_opened                          && If the catalog is now open
  82.  
  83.     SELECT FXCatalog
  84.     ln_code = -1                        && Assume the worst
  85.     DO _CatCode WITH pc_fname, ln_code  && Get the code for the file
  86.  
  87.     IF ln_code > -1                     && If the code exists
  88.  
  89.       FXC_ctag = UPPER( tag )
  90.  
  91.       *-- Now look for a matching DBF reference based on code
  92.       *-- Assume that the type is always lowercase.  Vue files are
  93.       *-- not included.
  94.       LOCATE FOR ( LOWER( type ) $ "dbf,qbe" ) .AND. ;
  95.                  code = ln_code
  96.  
  97.       IF FOUND()
  98.  
  99.         pc_result = TRIM(FXCatalog->path) && Store matching dbf/qbe to result
  100.  
  101.         IF LOWER( FXCatalog->type ) = "qbe" && If it's a qbe file
  102.           pl_isqbe = .T.                && Let the calling program know it
  103.         ENDIF
  104.  
  105.       ENDIF
  106.  
  107.     ENDIF
  108.  
  109.     IF .NOT. pl_catopnd                 && If catalog wasn't open before
  110.       DO _CatClose                      && Close the catalog
  111.     ENDIF
  112.  
  113.   ENDIF
  114.  
  115.   IF .NOT. ISBLANK( lc_alias )          && And there was a file open already
  116.     SELECT ( lc_alias )                 && Re-select the beginning work area
  117.   ENDIF
  118.  
  119.   IF ll_catalog
  120.     SET CATALOG ON
  121.   ENDIF
  122.  
  123. RETURN
  124. *-- EOP: _Cat4Dbf WITH pc_fname, pc_result, pl_isqbe, pl_catopnd
  125.  
  126.